import http from '@/api'
import { ADMIN_MODULE } from '@/api/helper/prefix'
import type { IPage } from '@/api/types';
import type { NovelDictQuery, NovelDictRow, NovelDictForm } from '@/api/types/novel/novelDict'
import type { UploadRawFile } from "element-plus/es/components/upload/src/upload";
import type { AxiosRequestConfig } from 'axios';

/**
* 查询列表
* @param params
* @returns {*}
*/
export const getNovelDictListApi = (params: NovelDictQuery) => {
  return http.get<IPage<NovelDictRow>>(ADMIN_MODULE + `/novel-dict`, params)
}

/**
* 添加
* @param params
* @returns {*}
*/
export const createNovelDictApi = (params: NovelDictForm) => {
  return http.post(ADMIN_MODULE + `/novel-dict`, params)
}

/**
* 修改
* @param params
* @returns {*}
*/
export const updateNovelDictApi = (params: NovelDictForm) => {
  return http.put(ADMIN_MODULE + `/novel-dict`, params)
}

/**
* 删除
* @param params
* @returns {*}
*/
export const removeNovelDictApi = (params: { ids: (string | number)[] }) => {
 return http.delete(ADMIN_MODULE + `/novel-dict`, params)
}

/**
* 查询详情列表
* @param params
* @returns {*}
*/
export const getNovelDictApi = (params: { id: number }) => {

  const { id } = params
  return http.get<NovelDictRow>(ADMIN_MODULE + `/novel-dict/${id}`)
}

/**
 * 获取字典
 * @param params
 * @returns {*}
 */
export const getNovelDictDetailApi = (params: { id: number }) => {

  return http.get<IPage<NovelDictRow>>(ADMIN_MODULE + `/novel-dict-detail`, { dictId : params.id } )
}

/**
 * 编辑字典
 * @param params
 * @returns {*}
 */
export const editNovelDictDetailApi = (params: any) => {

  return http.post<IPage<NovelDictRow>>(ADMIN_MODULE + `/novel-dict/saveAll`, params )
}

/**
 * 删除字典项
 * @param params
 * @returns {*}
 */
export const deleteNovelDictDetailApi = (params: { ids: (string | number)[] }) => {
  return http.delete(ADMIN_MODULE + `/novel-dict-detail`, params)
}

/**
* 导入excel
* @param params
*/
export const importNovelDictExcelApi = (params : UploadRawFile, config?: AxiosRequestConfig<any> | undefined) => {
  return http.upload(ADMIN_MODULE + `/novel-dict/import`, params, config)
}

/**
* 导出excel
* @param params
* @returns {*}
*/
export const exportNovelDictExcelApi  = (params: NovelDictQuery) => {
  return http.download(ADMIN_MODULE + `/novel-dict/export`, params)
}